package com.updesignsz.admin.mapper;

import com.updesignsz.commom.entity.RoleFunction;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * TODO 角色功能关系
 * Created User: lx
 * Date: 2020/4/28 15:11
 */
@Repository
@Mapper
public interface RoleFunctionMapper {

    @Select("SELECT GROUP_CONCAT(function_id) AS functionId FROM t_role_function where role_id = #{roleId}")
    String getRoleFunctionId(@Param("roleId") Integer roleId);

    @Delete({"delete from t_role_function where role_id  = #{roleId}"})
    void deleteRoleFunction(@Param("roleId") Integer roleId);



    @Insert({
            "<script>",
            "insert into t_role_function (role_id, function_id, created_date, updated_date)",
            "values ",
            "<foreach collection='resultList' item='item' index='index' separator=','>",
            "(#{item.roleId}, #{item.functionId}, NOW(),  NOW())",
            "</foreach>",
            "ON DUPLICATE KEY UPDATE `updated_date` = VALUES(`updated_date`)",
            "</script>"
    })
    int batchInsert(@Param(value = "resultList") List<RoleFunction> resultList);
}
